<template>
	<view class="list">
		<!-- <view class="header">
			<view class="search">
				<image src="@/static/img/healthStatus/search@2x.png" mode=""></image>
				<input type="text" placeholder="姓名">
			</view>
		</view> -->
		
		<view class="mainContent">
			<view class="listMular" v-if="list && list.length > 0">
				<uni-swipe-action>
					<view class="box" v-for="(item,index) in list" :key="index">
						<image src="@/static/img/monitor/healthStatus/number@2x.png" class="identifier"></image>
						<uni-swipe-action-item :right-options="options" @click="bindClick(item)">
							<view class="top">
								<text class="assementNumber">{{item.status == 1 ? '评估编号' : item.medicalNumber}}
									<image src="@/static/img/monitor/healthStatus/imgIcon@2x.png" class="physicalExamination" v-if="item.type != 2"></image>
									<image src="@/static/img/monitor/healthStatus/pdfIcon@2x.png" class="physicalExamination" v-else></image>
								</text>
								<text :class="item.status == 1 ? 'dataTime1' : 'dataTime'">{{item.status == 1 ? '未存档' : item.medicalTime}}</text>
							</view>
							<view class="bottom">
								<view class="nameBox">
									<text class="userName">{{item.realName ? item.realName : item.userName}}</text>
									<image src="@/static/img/monitor/healthStatus/getItem@2x.png" v-if="item.sources == 3 && item.status == 2"></image>
									<text class="healthName"  v-if="item.sources ==3 && item.status == 2">{{item.signName}}</text>
								</view>
								<view class="buttonBox">	
									<view class="qsDetail" @click="viewReport(item)" v-if="item.type == 2">查看报告</view>
									<view class="qsDetail" @click="detail(item)" v-else>详情</view>
									<view class="applyFor" @click="savestate(item)" v-if="item.status == 1">确认存档</view>
								</view>
							</view>
						</uni-swipe-action-item>
					</view>
				</uni-swipe-action>
			</view>	
			
			<view class="noData" v-else>
				<image src="@/static/img/healthStatus/none.png"></image>
				<view>暂无数据~</view>
			</view>
			
			<view class="location">
				<image src="@/static/img/monitor/healthStatus/add@2x.png"  @click="addQuestion"></image>
			</view>
		</view>
	</view>
</template>


<script>
	import {filterData2} from '@/static/js/filter.js';
	export default {
		data() {
			return {
				list: null,
				pageIndex: 1,
				pageSize: 10,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' // 删除按钮背景  红的
					}
				}],
				page:1,
				deleteList:'',
				nullData: false,
			}
		},
		onLoad(){
			this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize})
		},
		onReachBottom() {
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist({pageIndex:this.page,pageSize:this.pageSize})
		},
		methods:{
			filterData2,
			getlist(data){
				this.$api.MedicalList(data).then((res)=>{
					var data = res.data.result && res.data.result.elements.map((a)=> {
						a.updateTime = this.filterData2(a.updateTime);
						return a
					});
					if(this.deleteList == 1) {
						this.list = []
						this.list = data;
						this.deleteList = ''
					}else {
						this.list = this.list ? this.list.concat(data) : data
					}
					if(this.list.length >= res.data.result.totalCount){
						this.nullData = true;
					}
				})
			},
			detail(e) {
				if(e.status == 1) {
					uni.navigateTo({
						url:'/pages/monitor/medicalReport/uploadPhoto?id='+e.id+'&status='+e.status+'&signName='+e.signName
					})
				}else {
					uni.navigateTo({
						url:'/pages/monitor/medicalReport/photoView?id='+e.id
					})
				}
				
			},
			savestate(e) {
				const data = {
					id:e.id,
					medicalName:e.medicalName,
					medicalTime:e.medicalTime,
					imgUrls:e.imgUrls,
					status:2,
					type:1,
					userId:e.userId
				}
				this.$api.Medicalupdate(data).then((res) => {
					if(res.data.returnCode == 200) {
						uni.showToast({
							title:'存档成功',
							icon: 'none'
						})
						this.deleteList = 1;
						this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize})
					}
				})
			},
			bindClick(e) {
				const id = e.id;
				this.$api.MedicaldelId(id).then((res) => {
					if(res.data.returnCode == '200') {
						uni.showToast({
							title: '删除成功',
							icon: 'none'
						})
						this.page = 1
						this.deleteList = 1;
						this.nullData = false;
						this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize})
					}
				})
			},
			viewReport(e) {
				window.open('http://health.jlm12580.com/web/viewer.html?file='+e.imgUrls[0])
			},
			addQuestion(){
				uni.navigateTo({
					url:'/pages/monitor/medicalReport/entryPage'
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	/deep/ .uni-swipe_box{
		display: block !important;
	}
	/deep/.uni-swipe_button{
		padding: 0 20rpx;
		margin-left: 10rpx;
	}
	.list {
		background-color: #F8F8F8;
		width: 750upx;
		min-height: calc(100vh - 44px);
		padding-bottom: 140upx;
		.header {
			position: fixed;
			top: 88upx;
			left: 0;
			width: 750upx;
			height: 102upx;
			background: #05C6AD;
			display: flex;
			align-items: center;
			z-index: 100;
			.search {
				display: flex;
				align-items: center;
				width: 700upx;
				height: 54upx;
				background: #FFFFFF;
				border-radius: 27upx;
				margin: auto;
				image {
					width: 22upx;
					height: 22upx;
					margin: 0 24upx;
				}
				input {
					font-size: 24upx;
				}
			}
		}
		
		.mainContent {
			width: 702upx;
			margin:0 auto;
			padding-top: 24upx;		
			.listMular {
				width: 702upx;
				border-radius: 22upx;
				.box {
					width: 100%;
					height: 100%;
					background: #FFFFFF;
					border-radius: 22upx;
					padding:0 29upx 0 40upx;
					box-sizing: border-box;
					position: relative;
					margin-bottom: 25upx;
					.identifier{
						position: absolute;
						left: -6upx;
						top: 13%;
						width: 32upx;
						height: 30upx;
					}
					.top {
						height: 74upx;
						display: flex;
						align-items: center;
						font-size: 28upx;		
						border-bottom: 1upx solid #CCCCCC;
						.assementNumber {
							flex: 1;
							color: #666666;
							margin-left: 6upx;
							.physicalExamination {
								width: 50upx;
								height: 25upx;
								margin-left: 12upx;
							}
						}
						.assementType,.dataTime1 {
							color: #EA0B0B;
							flex: 1;
							text-align: right;
						}
						.dataTime {
							color: #666666;
						}
					}
					.bottom {
						display: flex;
						align-items: center;
						height: 97upx;
						.nameBox {
							flex: 1;
							display: flex;
							align-items: baseline;
							.userName {
								margin-left: 10upx;
								color: #000000;
								font-size: 40upx;
							}
							image {
								width: 24upx;
								height: 24upx;
								margin: 0 12upx 0 18upx;
							}
							.healthName {
								color: #05C6AD;
								font-size: 26upx;
							}
						}
						.buttonBox {
							display: flex;
							.qsDetail,
							.applyFor,
							.generating,
							.viewAssessment{
								width: 146upx;
								height: 50upx;
								background: #6AB7FF;
								border-radius: 25upx;
								color: #FFFFFF;
								font-size: 30upx;
								line-height: 50upx;
								text-align: center;
							}
							.applyFor {
								background-color: #05C6AD;
								margin-left: 24upx;
							}
						}
					}
				}
			}
			.noData {
				image {
					width: 260upx;
					height: 200upx;
					display: table;
					margin: 246upx auto 32upx;
				}
				view {
					text-align: center;
					color: #666666;
					font-size: 30upx;
				}
			}
		}
		.location {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750upx;
			height: 135upx;
			background: url('@/static/img/monitor/healthStatus/suspensionBg@2x.png') no-repeat;
			background-size: 100% 100%;
			image {
				position: fixed;
				bottom: 26upx;
				left: 50%;
				transform: translateX(-50%);
				width: 90upx;
				height: 90upx;
			}
		}
	}
</style>
